﻿using System;

namespace FluentSpring
{
    public class PropertyDependencyStep:IDependencyStep 
    {
        private String propertyName;
        private ConfigContext configContext;
        private ConfigStep origin;

        public PropertyDependencyStep(String propertyName, ConfigContext configContext, ConfigStep origin)
        {
            this.propertyName = propertyName;
            this.configContext = configContext;
            this.origin = origin;
        }

        #region IDependencyStep Members

        public ConfigStep To(string refName)
        {
            BuilderAction action =
                builder => builder.AddPropertyReference(propertyName, refName);            
            configContext.BuilderActionList.Add(action);

            return origin;
        }

        public ConfigStep To<T>()
        {
            BuilderAction action =
                builder => builder.AddPropertyReference(propertyName, typeof(T).FullName);
            configContext.BuilderActionList.Add(action);

            return origin;

        }

        public ConfigStep To(ObjectFactoryDelegate objectFactoryDelegate)
        {
            BuilderAction action =
                builder => builder.AddPropertyValue(propertyName, objectFactoryDelegate());
            configContext.BuilderActionList.Add(action);
            return origin;
        }
        #endregion
    }
}
